﻿using System;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Text;

namespace NPMonitor.Implementation.Mail
{
    public static class CommUtil
    {

        public static string CreateHtmlBody(string htmlFile, params object[] objs)
        {
            string rawHtml = GetHtmlFromResource(htmlFile);
            return String.Format(CultureInfo.InvariantCulture, rawHtml, objs);
        }

        private static string GetHtmlFromResource(string htmlFile)
        {
            using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(
               "NPMonitor.Implementation.Mail.MailHtml." + htmlFile))
            {
                byte[] buffer = new byte[s.Length];
                s.Position = 0;
                s.Read(buffer, 0, (int)s.Length);
                return Encoding.UTF8.GetString(buffer);
            }
        }
    }
}
